<?php
    $msg_1 = addslashes($_POST['msg_1']);
    
    $sql = "UPDATE text_data SET td_th='$msg_1' WHERE td_id=10";
    $result = $db->Execute($sql);
    
    if($result){
        $msg = 'บันทึกข้อมูลเรียบร้อยแล้ว';
        if($_FILES['img_1']['name']!='')
        {
            $handle = new Upload($_FILES['img_1']);
            if ($handle->uploaded)
            {
                if($handle->image_src_x > 795){
                    $handle->image_resize = true;
                    $handle->image_x = 795;
                    $handle->image_ratio_y = true;
                }
                
                $handle->Process(APPPATH.'/images');
    
                if ($handle->processed)
                {
                    $sql = 'UPDATE img_data SET id_path="'.$handle->file_dst_name.'" WHERE id_id=7';
                    $result =$db->Execute($sql);
                    if($result)
                    {
                        if(img_exists(APPPATH.'/images',$_POST['img_1_old'])){
                            @unlink(APPPATH.'/images/'.$_POST['img_1_old']);
                        }
                        $msg = 'บันทึกข้อมูลเรียบร้อยแล้ว';
                    }
                    else
                    {
                        if(img_exists(APPPATH.'/images',$handle->file_dst_name)){
                            @unlink(APPPATH.'/images/'.$handle->file_dst_name);
                        }
                        $msg = 'ไม่สามารถอัพโหลดรูปได้';
                    }
                }
                else
                {
                    $msg = 'ไม่สามารถอัพโหลดรูปได้';
                }
    
            }
            else
            {
                $msg = 'ไม่สามารถอัพโหลดรูปได้';
            }
        }
    }else{
        $msg = 'ไม่สามารถบันทึกข้อมูลได้';
    }
?>

<?php
    include('header.php');
    include('submenu.php');
?>
<div class="grid_18" id="contents">
    <div id="query_result">
    <?php
        echo $msg , ' <img src="images/ajax-loader.gif" />';
        redirect('?m=shape-size&s=custom-made-shape',3);
    ?>
    </div>
</div><!-- end .grid_18 -->
<div class="clear">&nbsp;</div>
<?php
    include('footer.php');
?>